<?php
require_once '../includes/global.php';
//Jc(p);
if($_GET[op]=='deluser') {
    $ar['del']=1;

    @Du('user',$ar,'id',$_GET[id]);

    Jt($_SERVER['HTTP_REFERER'],'删除成功');
}
if($_GET[op]=='add') {
    $temp=Dgs('sort',"parentid = '33'");
    //Jc($temp);
    $i=0;
    foreach ($temp as $value) {
        if ($value[title]!='') {
            $yin[$i]=$value[id];
            $xuan[$i]=$value[title];
            $i++;
        }

    }
    $tmp=Bcs("department",$yin,$xuan,0,'0','请选择部门');
    //Jc($yin);
    Tr($tmp,'department');
    $ttt->assign("op","insertuser");
    Ts("mod/useradd.htm");
}
if($_POST[op]=='insertuser') {
    $p=Dga('user',"user = '".$_POST[user]."'");
    if($p!='') {
        Ja('用户存在');
        Jt($_SERVER['HTTP_REFERER'],'用户存在');
    }
    $_POST[id]="";
    $_POST[psw]=md5($_POST[psw]);
    $_POST[regtime]=time();
    Di("user",$_POST);
    Jt("user.php?op=list",'添加成功');
}

if($_GET[op]=='list') {
//print_r($_GET);
//$ttt->assign('kg',$_GET[kg]);
/*if($_GET[kg]=='')
{
$_GET[kg]='-1';
}
*/
    if(isset($_GET[offset]) and isset($_GET[pageline])) {
        $classtest = new tviewpage($prefix.'_user',$_GET[pageline],$_GET[offset]);
    //echo "GET";
    }
    else {

        $offset=0;
        $pageline=12;
        $classtest = new tviewpage($prefix.'_user',$pageline,$offset);

    //echo "none";
    }
    //Jc('s');
    if($_SESSION[userinfo]['rcfg']!='S') {
        $condition=" and user like '".$_SESSION[userinfo][user]."'";
    }



    $classtest->setCondition(" where 1 ".$condition." and del!=1 ORDER BY `id`  DESC  ");

    $classtest->setPageQuery('op','list');
    //$classtest->setPageQuery('kg',$_GET[kg]);

    $recordset = $classtest->getRecords();
    ob_start();
    $classtest->showFullFunc();
    $nav = ob_get_contents();
    ob_end_clean();
    $ttt->assign("nav","$nav");


    $j = count($recordset);

    for($t=0;$t<$j;$t=$t+1) {
        if ($recordset[$t]['user']=='admin' && $_SESSION['userinfo']['user']!='admin') {
            continue;
        }
        $recordset[$t][department]=Sidtitle($recordset[$t][department]);
        $fu="
            〖<a href='#' onclick=\"showorhidden(j".$recordset[$t][id].")\">修改密码</a>〗</TD>
        </TR>
        <tbody name='j".$recordset[$t][id]."' id='j".$recordset[$t][id]."' style=\"display:none;\">
            <tr>
                <td colspan=7 bgColor=#ffffff >
                    <form method=post op=mod.php name='form".$recordset[$t][id]."'>
                        新密码明文:<input name='psw' type=text  size=15>

                        <input type=hidden name=op value=upzt>
                        <input type=hidden name=id value=".$recordset[$t][id].">

                        <input type=submit value='－更新－'>

                    </form>
                </td>
            </tr>
        </tbody>
      ";
        $w=Dga('rcfg',"id =".$recordset[$t][rightid]);

        $content.="
        <tr class=\"tbhead\">
            <td width=\"11%\" nowrap  >".$recordset[$t][id]."&nbsp;</td>
            <td width=\"26%\" nowrap  >".$recordset[$t][user]."&nbsp;</td>
            <td width=\"11%\" nowrap  title='intro:".$recordset[$t][info]."'>".$recordset[$t]['name']."&nbsp;</td>
            <td width=\"11%\" nowrap  >".$recordset[$t]['chenggong']."&nbsp;</td>
            <td width=\"11%\" nowrap  >".$recordset[$t]['xinyong']."&nbsp;</td>
            <td width=\"11%\" nowrap  >".$recordset[$t]['haoping']."&nbsp;</td>
            <td width=\"11%\" nowrap  >".$recordset[$t]['tel']."&nbsp;</td>
            <td width=\"11%\" nowrap  >".date("Y-m-d",$recordset[$t][regtime])."&nbsp;</td>
            <td width=\"63%\" align=\"center\" nowrap>
                ".(($_SESSION[userinfo][rcfg]=='S')?(" 〖<a href=\"?op=mod&id=".$recordset[$t][id]."\">编辑</a>〗
                〖 <a href=\"?op=deluser&id=".$recordset[$t][id]."\">删除</a>〗"):(''))."
                ".$fu."
            </td>
        </tr>";
    }


    $ttt->assign("content",$content);
    Ts("mod/user_list.htm");
}
if($_POST[op]=='updateuser') {
    Du("user",$_POST,'id',$_POST[id]);
    Jt("user.php?op=list",'更新成功！');
}

if($_POST[op]=='updateright') {
//print_r($_POST);
    Du("user",$_POST,'id',$_POST[id]);
    Jt("user.php?op=right&mid=50&from=b");
}





/**/
if($_GET[op]=='mod') {
    $w=Dga('user',"id =".$_GET[id]);

    $temp=Dgs('sort',"parentid = '33'");
    //Jc($temp);
    $i=0;
    foreach ($temp as $value) {
        if ($value[title]!='') {
            $yin[$i]=$value[id];
            $xuan[$i]=$value[title];
            $i++;
        }

    }
    //$w[department]=Bcs("department",$yin,$xuan,$w[department],'0','请选择部门');
    //Jc($yin);
    foreach($w as $r => $t) {
        $ttt->assign($r,$t);
    }

    $ttt->assign("notice","不可更改");
    $ttt->assign("kg","1");
    $ttt->assign("op","updateuser");
    Ts("mod/useradd.htm");
}




if($_GET[op]=='rightapply') {

    $ttt->assign('id',$_GET[id]);
    $sort= Dgs('rcfg',"1 and del !='1' ");
    $mtemp=Dga('user'," id = '".$_GET[id]."'");
    foreach($sort as $temp) {
        if($mtemp[rightid]==$temp[id]) {
            $selectinfo.="<option  value='".$temp[id]."'  selected>".$temp['title']."</option>";
        }
        else {
            $selectinfo.="<option  value='".$temp[id]."'>".$temp['title']."</option>";
        }
    }
    $ttt->assign("sortlist",$selectinfo);
    $ttt->assign("op","updateright");

    Ts("mod/rightaply.htm");
}


if($_GET[op]=='right') {
//print_r($_GET);
//$ttt->assign('kg',$_GET[kg]);
/*if($_GET[kg]=='')
{
$_GET[kg]='-1';
}
*/
    if(isset($_GET[offset]) and isset($_GET[pageline])) {
        $classtest = new tviewpage($prefix.'_user',$_GET[pageline],$_GET[offset]);
    //echo "GET";
    }
    else {

        $offset=0;
        $pageline=64;
        $classtest = new tviewpage($prefix.'_user',$pageline,$offset);

    //echo "none";
    }
/* òѯ
if($_GET[id]!=''){
$condition=" where 1";
	if($_GET[id]==0){
$_SESSION[condition]=$condition;
	}
	else
	{
$condition.=" and sortid =".$_GET[id];
$_SESSION[condition]=$condition;
	}
}*/
    $classtest->setCondition("where user like '%".$_GET[user]."%' and del !='1' and rcfg ='M'  ORDER BY `id`  DESC  ");

    $classtest->setPageQuery('op','right');
    //$classtest->setPageQuery('kg',$_GET[kg]);

    $recordset = $classtest->getRecords();
    ob_start();
    $classtest->showFullFunc();
    $nav = ob_get_contents();
    ob_end_clean();
    $ttt->assign("nav","$nav");


    $j = count($recordset);

    $content.="<tr bgcolor='ffffff'>";
    for($t=0;$t<$j;$t=$t+1) {

        $rtemp=Dga('rcfg',"id='".$recordset[$t][rightid]."'");
        if(($t+1)%8==0) {
            $content.="<td bgcolor='ffffff' title='Right template :".$rtemp[$_SESSION[LG]]."'><a href=\"?op=rightapply&id=".$recordset[$t][id]."\">".$recordset[$t][user]."</a></td></tr><tr bgcolor='ffffff'>";
        }
        else {
            $content.="<td bgcolor='ffffff' title='Right template :".$rtemp[$_SESSION[LG]]."'><a href=\"?op=rightapply&id=".$recordset[$t][id]."\">".$recordset[$t][user]."</a></td>";
        }

    }
    $content.="</tr>";

    $ttt->assign("content",$content);
    Ts("mod/member.htm");
}
if($_POST[op]=='upzt') {
    $arPw[psw]=md5($_POST[psw]);
    Du('user',$arPw,'id',$_POST[id]);
    Jt($_SERVER['HTTP_REFERER'],'改密成功');

}

?>
